package com.util;

import java.io.Serializable;

/**
 * 排序助手
 */
public class OrderAssistant implements Serializable {

    /** 排序使用的字段 */
    private String column;
    /** 排序的方式(0升序, 1降序)*/
    private String state;

    /**
     * 获取排序的sql语句
     * @return
     */
    public String sql(){

        if (column == null || column.equals("")){
            column = "id";
        }
        if (state == null || state.equals("")){
            state = "0";
        }

        return column + (state.equals("0") ? " asc" : " desc");
    }

    @Override
    public String toString() {
        return "OrderAssistant{" +
                "column='" + column + '\'' +
                ", state='" + state + '\'' +
                '}';
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }
}
